/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/11/2
 * Time: 11:25
 * Description:
 */
public class MyQueue {
    static class Node {
        public int val;
        public Node next;
        public Node(int val) {
            this.val = val;
        }
    }
    public Node first;
    public Node last;

    //尾插法 入队
    public void offer(int val) {
        Node node = new Node(val);
        if(this.first == null) {
            this.first = node;
            this.last = node;
        }else {
            this.last.next = node;
            this.last = node;
        }
    }
    //出队
    public int poll() {
        if(isEmpty()) throw new RuntimeException("队列为空");
        int val = this.first.val;
        this.first = this.first.next;
        return val;
    }

    public boolean isEmpty() {
        return this.first == null;
    }
    //获取队头元素
    public int peek() {
        if(isEmpty()) throw new RuntimeException("队列为空");
        return this.first.val;
    }
}
